<template>
  <div>
    <el-form label-width="100px" class="demo-ruleForm" size="small ">
      <el-form-item label="用户名">
        <el-input
          clearable
          v-model="userInfo.username"
          placeholder="请输入内容"
        />
      </el-form-item>
      <el-form-item label="密码"
        ><el-input clearable v-model="userInfo.pwd" placeholder="请输入内容"
      /></el-form-item>
      <el-form-item>
        <el-checkbox
          label="记住用户名"
          v-model="userInfo.checked"
        ></el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="button" @click="Login">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userInfo: {
        username: "",
        pwd: "",
        checked: false,
      },
    };
  },
  methods: {
    Login() {
      if (!this.userInfo.username || !this.userInfo.pwd) {
        this.$message({
          type: "waring",
          message: "密码或用户名不能为空",
        });
        return;
      }
      if (this.userInfo.checked) {
        this.userInfo.jurisdiction="2"
        localStorage.setItem("userInfo", JSON.stringify(this.userInfo));
      }
      localStorage.setItem("token", "asdgasgdds");
      this.$router.replace("/home")
    },
  },
  created() {
    const user = JSON.parse(localStorage.getItem("userInfo"))
      ? JSON.parse(localStorage.getItem("userInfo"))
      : {};
    if (!user) {
      return;
    } else {
      if (user.checked) {
        this.userInfo = { ...user };
      }
    }
  },
};
</script>

<style lang="scss" scoped>
.demo-ruleForm {
  width: 50%;

  margin: auto;
  position: fixed;
  top: 30%;
  bottom: 50%;
  left: 0;
  right: 0;
}
</style>